package com.atguigu.tingshu.user.pattern.fac;

import com.atguigu.tingshu.user.pattern.UserPaidStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: atguigu
 * @create: 2024-04-23 14:52
 */
@Slf4j
@Component
public class StrategyFactory {


    /**
     * Spring注入类型如果是Map 自动将Map中Value类型对象注入到Map
     * Key:BeanID，Value：实现类对象
     */
    @Autowired
    private Map<String, UserPaidStrategy> strategyMap;


    /**
     * 根据购买项目类型获取不同策略实现类对象
     * @param itemType
     * @return
     */
    public UserPaidStrategy getPaidStrategy(String itemType){
        if (strategyMap.containsKey(itemType)) {
            return strategyMap.get(itemType);
        }
        throw new RuntimeException("该项目类型不支持");
    }

}
